import mysql.connector


def get_con():
    con = None
    try:
        con = mysql.connector.connect(
            host='127.0.0.1',
            port='3306',
            user="root",
            password='root',
            database='examtest',
            auth_plugin='mysql_native_password'

        )

    except mysql.connector.Error as e:
        print(str(e))

    return con


def get_sql_content(table_name, *args):
    con = get_con()
    cursor = con.cursor()
    sql = "select "
    if len(args) != 0:
        for i in range(0, len(args)):
            if i == len(args) - 1:
                sql += args[i]
            else:
                sql += args[i]
                sql += ","
    sql += " from " + table_name
    print(sql)
    cursor.execute(sql)
    result = cursor.fetchall()
    cursor.close()
    con.close()
    return result


if __name__ == '__main__':
    for item in get_sql_content('ecshop_user_register', 'user_name', 'user_email', 'pass_word',
                                'con_pass_word', 'user_msn', 'user_qq', 'work_tel', 'home_tel', 'tel', 'user_question',
                                'user_answer'):
        print(item)
